package product;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JTextField;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.print.PrinterException;
import java.awt.Font;
import java.awt.Color;

public class Admin extends JPanel {

	DefaultTableModel model = new DefaultTableModel(); //사번별
	DefaultTableModel model2 = new DefaultTableModel();//직책별
	DefaultTableModel model4 = new DefaultTableModel();//부서별
	ManagerChart p = null;//그래프
	DefaultTableModel model5 = null;//날짜별
	Vector<String> colName = new Vector<String>();
	Vector<String> test = new Vector<String>(); // 집합된 데이터들을 저장할 벡터
	boolean hdFlag;//유급 휴가창 오픈 유무
	
	String ym1,ym2,ym3,ym4;//년월,직책,부서,사번 검색한 년월저장
	Hollyday hd = new Hollyday(this);
	
	String [] su = {"01","02","03","04","05","06","07","08","09","10","11","12","전체"};//월
	String [] su2 = {"14","13","12","11","10","09","08","07","06","05","04","전체"};//년
	MethodClass mc = new MethodClass();
	long tot;//인건비 총합
	SalarySQL db;
	Connection con;
	
	private JTabbedPane tabbedPane;
	private JPanel panel_2;
	private JPanel panel;
	private JPanel panel_4;
	private JScrollPane scrollPane_1;
	private JTable table_1;
	private JComboBox comboBox_1;
	private JPanel panel_5;
	private JScrollPane scrollPane_2;
	private JTable table_2;
	private JComboBox lvCombo;
	private JPanel panel_6;
	private JPanel panel_7;
	private JScrollPane scrollPane_3;
	private JTable table_3;
	private JTextField search;
	private JLabel lblNewLabel_1;
	private JButton btnNewButton_2;
	private JComboBox comboBox;
	private JComboBox lvYCom;
	private JComboBox lvMCom;
	private JComboBox sbMCom;
	private JComboBox sbYCom;
	private JPanel panel_1;
	private JLabel lblNewLabel;
	private JPanel panel_3;
	private JButton btnNewButton_4;
	private JButton btnNewButton_5;
	private JButton btnNewButton_6;
	private JPanel panel_8;
	private JPanel panel_10;
	private JPanel panel_9;
	private JComboBox teamCombo;
	private JComboBox teamMCom;
	private JComboBox teamYCom;
	private JScrollPane scrollPane;
	private JTable table;
	private JButton btnNewButton;
	private JButton button;
	private JButton button_1;
	private JPanel panel_11;
	private JPanel panel_12;
	private JComboBox year;
	private JLabel lblNewLabel_2;
	private JButton btnNewButton_1;
	private JLabel lblNewLabel_3;
	private JLabel lblresult1;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel lblresult2;
	private JLabel label_4;
	private JLabel label_6;
	private JLabel label_7;
	private JLabel lblresult3;
	private JLabel lblresult4;


	public Admin(Connection conn) {
		this.con = conn;
		db = new SalarySQL(conn);
		
		setLayout(new BorderLayout(0, 0));

		colName.add("사원번호");
		colName.add("부서별");
		colName.add("직책");
		colName.add("성명");
		colName.add("일당");
		colName.add("출근일수");
		colName.add("유급휴가");
		colName.add("급여");

		add(getTabbedPane(), BorderLayout.CENTER);
		add(getPanel_1(), BorderLayout.NORTH);

		JTableHeader jh1 = table.getTableHeader();
		JTableHeader jh2 = table_1.getTableHeader();
		JTableHeader jh3 = table_2.getTableHeader();
		JTableHeader jh4 = table_3.getTableHeader();
		jh1.setReorderingAllowed(false);//컬럼 이동 금지
		jh2.setReorderingAllowed(false);
		jh3.setReorderingAllowed(false);
		jh4.setReorderingAllowed(false);
		//jh1.setResizingAllowed(false);//컬럼 사이즈 변경 금지

		mc.setDB(conn); // MethodClass에 로그인 클래스의 커넥션 객체 연동.
		//시작하자마자 년월 전체 조회 하기 위해서
		search("년월 조회", "전체년", "전체월", "", model5);
		int rowCNT1 = model5.getRowCount();
		lblresult1.setText(rowCNT1+"건이 검색 되었습니다.");
	}

	public void sabernSearch(){
		String id = search.getText().trim();
		lblNewLabel_1.requestFocus();
		if(id.equals("")){
			JOptionPane.showMessageDialog(table_3, 
					"조회 하실 사번을 입력해주세요!","경고창",JOptionPane.ERROR_MESSAGE);
			return;
		}
		int check = db.memCheck(id);
		if(check == 1){
			String sby = (String)sbYCom.getItemAt(sbYCom.getSelectedIndex());
			String sbm = (String)sbMCom.getItemAt(sbMCom.getSelectedIndex());
			search("검색", sby, sbm, id, model);
			int rowCNT4 = model.getRowCount();
			lblresult4.setText(rowCNT4+"건이 검색 되었습니다");
			if(model.getRowCount()==0){
				lblresult4.setText("검색된 데이타가 없습니다");
				JOptionPane.showMessageDialog(table_3, "검색된 데이타가 없습니다","경고창",JOptionPane.ERROR_MESSAGE);
			}
		}else{
			JOptionPane.showMessageDialog(table_3, 
					id+"은 없는 사번입니다\n사번을 다시 확인해주세요","경고창",JOptionPane.ERROR_MESSAGE);
		}
	}
	
	public void mouseC(JTable table,int s){
		int index = table.getSelectedColumn();// 선택된 열의 table index번호를 저장
		hd.setAlwaysOnTop(true);//상세휴가창이 항상 위에
		String ym="";
		if(index == 6){ // 유급휴가 열을 눌렀으면
			if(hd.getState() == 1){//최소화 상태라면 원래 위치로 돌아오거라
				hd.setState(0);
			}
			
			//테이블 선택된거 초기화?
			if(hd.model != null) hd.table.setSelectionMode(0);
			//테이블 스크롤봐 항상 맨위로
			hd.scrollPane.getVerticalScrollBar().setValue(hd.scrollPane.getVerticalScrollBar().getMinimum());
			hd.setVisible(true);
			hdFlag=true;
			int idxrow = table.getSelectedRow();// 선택된 행의 table index번호를 저장
			String id = (String)table.getValueAt(idxrow, 0);
			String name = (String)table.getValueAt(idxrow, 3);
			if(s!=4){
				if(s==1) ym=ym1;
				else if(s==2) ym=ym2;
				else if(s==3) ym=ym3;
				hd.setTable(id, name, ym, db);
			}else{
				ym=ym4;
				String su3=(String)table.getValueAt(idxrow, 8);
				if(su3.equals("전체 년/월")) su3="";
				else if(su3.contains("전체 년 / ")){
					su3=su3.substring(7, 9);
					su3="%/"+su3+"/";
				}
				else if(su3.contains(" / 전체 월")){
					su3=su3.substring(0,2);
					su3=su3+"/";
				}
				hd.setTable(id, name, su3, db);
			}
			
		}
	}
	
	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.setFont(new Font("굴림", Font.PLAIN, 11));
			tabbedPane.addMouseListener(new MouseAdapter() {
				@Override
				public void mousePressed(MouseEvent e) {

					if(tabbedPane.getSelectedIndex() == 4 && p == null){
						// 그래프 탭 선택했을때.
						p = new ManagerChart(con);//매개변수로 인건비 보냄
						p.total("14");
						JFreeChart chart = p.getChart(); // JFreeChart
						ChartPanel panel = new ChartPanel(chart);
						panel.setLayout(new BorderLayout(0,0));
						panel.setBounds(0, 0, 400, 300);
						panel.setVisible(true);
						panel_12.add(panel, BorderLayout.CENTER);
						//panel_10.add(new JButton("버튼"), BorderLayout.EAST);
					}
				}
			});

			tabbedPane.addTab("월  별", null, getPanel_2(), null);
			tabbedPane.addTab("직책별", null, getPanel_3(), null);
			tabbedPane.addTab("부서별", null, getPanel_8(), null);
			tabbedPane.addTab("사번별", null, getPanel_6(), null);
			tabbedPane.addTab("그래프", null, getPanel_10(), null);
		}
		return tabbedPane;
	}
	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel_4(), BorderLayout.NORTH);
			panel_2.add(getScrollPane_1_1(), BorderLayout.CENTER);
		}
		return panel_2;
	}
	private JPanel getPanel_3() {
		if (panel == null) {
			panel = new JPanel();
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getPanel_5(), BorderLayout.NORTH);
			panel.add(getScrollPane_2(), BorderLayout.CENTER);
		}
		return panel;
	}
	private JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setBackground(new Color(0, 0, 102));
			panel_4.add(getLabel());
			panel_4.add(getComboBox());
			panel_4.add(getComboBox_1());
			panel_4.add(getBtnNewButton());
			panel_4.add(getLblNewLabel_3());
			panel_4.add(getLblresult1());
		}
		return panel_4;
	}
	private JScrollPane getScrollPane_1_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setViewportView(getTable_1_1());
		}
		return scrollPane_1;
	}

	private JTable getTable_1_1() {
		if (table_1 == null) {
			model5 = new DefaultTableModel(colName, 0) {
				// 셀 내용 수정 불가
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			table_1 = new JTable(model5);

			table_1.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent e) {
					mouseC(table_1,1);
				}
			});

			table_1.setAutoCreateRowSorter(true);
			mc.tableCellCenter(table_1);
			mc.tableCellRight(table_1);
		}
		return table_1;
	}
	private JComboBox getComboBox_1() {
		if (comboBox_1 == null) {
			comboBox_1 = new JComboBox();
			comboBox_1.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su.length;i++){
				comboBox_1.addItem(su[i]+"월");
			}

			comboBox_1.setSelectedIndex(12);

		}
		return comboBox_1;
	}
	private JPanel getPanel_5() {
		if (panel_5 == null) {
			panel_5 = new JPanel();
			panel_5.setBackground(new Color(0, 0, 102));
			panel_5.add(getLabel_1());
			panel_5.add(getLvYCom());
			panel_5.add(getLvMCom());
			panel_5.add(getLvCombo());
			panel_5.add(getButton());
			panel_5.add(getLabel_2());
			panel_5.add(getLblresult2());
		}
		return panel_5;
	}
	private JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setViewportView(getTable_2());
		}
		return scrollPane_2;
	}
	private JTable getTable_2() {
		if (table_2 == null) {
			model2 = new DefaultTableModel(colName, 0) {
				// 셀 내용 수정 불가
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			table_2 = new JTable(model2);
			table_2.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent e) {
					mouseC(table_2,2);
				}
			});
			table_2.setAutoCreateRowSorter(true);
			mc.tableCellCenter(table_2);
			mc.tableCellRight(table_2);
		}
		return table_2;
	}
	private JComboBox getLvCombo() {
		if (lvCombo == null) {
			lvCombo = new JComboBox();
			lvCombo.setFont(new Font("굴림", Font.PLAIN, 11));
			lvCombo.addItem("직책");
			lvCombo.addItem("부장");
			lvCombo.addItem("과장");
			lvCombo.addItem("대리");
			lvCombo.addItem("사원");

		}
		return lvCombo;
	}
	private JPanel getPanel_6() {
		if (panel_6 == null) {
			panel_6 = new JPanel();
			panel_6.setLayout(new BorderLayout(0, 0));
			panel_6.add(getPanel_7(), BorderLayout.NORTH);
			panel_6.add(getScrollPane_3(), BorderLayout.CENTER);
		}
		return panel_6;
	}
	private JPanel getPanel_7() {
		if (panel_7 == null) {
			panel_7 = new JPanel();
			panel_7.setBackground(new Color(0, 0, 102));
			panel_7.add(getLabel_6());
			panel_7.add(getSbYCom());
			panel_7.add(getSbMCom());
			panel_7.add(getLblNewLabel_1());
			panel_7.add(getSearch());
			panel_7.add(getBtnNewButton_2());
			panel_7.add(getLabel_7());
			panel_7.add(getLblresult4());
		}
		return panel_7;
	}
	private JScrollPane getScrollPane_3() {
		if (scrollPane_3 == null) {
			scrollPane_3 = new JScrollPane();
			scrollPane_3.setViewportView(getTable_3());
		}
		return scrollPane_3;
	}
	private JTable getTable_3() {
		if (table_3 == null) {
			colName.add("년월");
			model = new DefaultTableModel(colName, 0) {
				// 셀 내용 수정 불가
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			table_3 = new JTable(model);
			table_3.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent e) {
					mouseC(table_3,4);
				}
			});

			table_3.setAutoCreateRowSorter(true);
			mc.tableCellCenter(table_3);
			mc.tableCellRight(table_3);
		}
		return table_3;
	}
	private JTextField getSearch() {
		if (search == null) {
			search = new JTextField();
			search.addKeyListener(new KeyAdapter() {
				@Override
				public void keyReleased(KeyEvent e) {
					if(e.getKeyCode() == 10){ // 10은 엔터키
						sabernSearch();
					}
				}
			});
			search.setColumns(5);
		}
		return search;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("    \uC0AC\uBC88 ");
			lblNewLabel_1.setForeground(new Color(255, 255, 255));
			lblNewLabel_1.setFont(new Font("굴림", Font.PLAIN, 11));
		}
		return lblNewLabel_1;
	}
	private JButton getBtnNewButton_2() {
		if (btnNewButton_2 == null) {
			btnNewButton_2 = new JButton("검색");
			btnNewButton_2.setFont(new Font("굴림", Font.PLAIN, 11));
			btnNewButton_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					sabernSearch();
				}
			});
		}
		return btnNewButton_2;
	}
	private JComboBox getComboBox() {
		if (comboBox == null) {
			comboBox = new JComboBox();
			comboBox.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su2.length;i++){
				comboBox.addItem(su2[i]+"년");
			}
			comboBox.setSelectedIndex(11);

		}
		return comboBox;
	}
	private JComboBox getLvYCom() {
		if (lvYCom == null) {
			lvYCom = new JComboBox();
			lvYCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su2.length;i++){
				lvYCom.addItem(su2[i]+"년");
			}
			lvYCom.setSelectedIndex(11);

		}
		return lvYCom;
	}
	private JComboBox getLvMCom() {
		if (lvMCom == null) {
			lvMCom = new JComboBox();
			lvMCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su.length;i++){
				lvMCom.addItem(su[i]+"월");
			}
			lvMCom.setSelectedIndex(12);

		}
		return lvMCom;
	}
	private JComboBox getSbMCom() {
		if (sbMCom == null) {
			sbMCom = new JComboBox();
			sbMCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su.length;i++){
				sbMCom.addItem(su[i]+"월");
			}
			sbMCom.setSelectedIndex(12);

		}
		return sbMCom;
	}
	private JComboBox getSbYCom() {
		if (sbYCom == null) {
			sbYCom = new JComboBox();
			sbYCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su2.length;i++){
				sbYCom.addItem(su2[i]+"년");
			}
			sbYCom.setSelectedIndex(11);

		}
		return sbYCom;
	}
	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setBackground(new Color(0, 0, 102));
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getLblNewLabel(), BorderLayout.NORTH);
			panel_1.add(getPanel_3_1(), BorderLayout.EAST);
		}
		return panel_1;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("    ");
			lblNewLabel.setFont(new Font("굴림", Font.PLAIN, 11));
			lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNewLabel;
	}
	private JPanel getPanel_3_1() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setBackground(new Color(0, 0, 102));
			panel_3.add(getBtnNewButton_4());
			panel_3.add(getBtnNewButton_5());
			panel_3.add(getBtnNewButton_6());
		}
		return panel_3;
	}
	private JButton getBtnNewButton_4() {
		if (btnNewButton_4 == null) {
			btnNewButton_4 = new JButton("엑셀 열기");
			btnNewButton_4.setRequestFocusEnabled(false);
			btnNewButton_4.setMnemonic('O');
			btnNewButton_4.setToolTipText("열기 단축키: [Alt+O]");
			btnNewButton_4.setFont(new Font("굴림", Font.PLAIN, 11));
			btnNewButton_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					
					mc.ExcelLoad();
					
				}
			});
		}
		return btnNewButton_4;
	}
	private JButton getBtnNewButton_5() {
		if (btnNewButton_5 == null) {
			btnNewButton_5 = new JButton("엑셀 저장");
			btnNewButton_5.setRequestFocusEnabled(false);
			btnNewButton_5.setMnemonic('S');//단축키 설정
			btnNewButton_5.setToolTipText("저장 단축키: [Alt+S]");
			btnNewButton_5.setFont(new Font("굴림", Font.PLAIN, 11));
			btnNewButton_5.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					MethodClass mc = new MethodClass();//공통된 메서드 모은 클래스

					switch(tabbedPane.getSelectedIndex()){
					case 0:
					{//테이블의 행이 있어야지 엑셀저장 실행됨
						if(table_1.getRowCount() != 0) mc.ExcelSave(table_1);
						break;
					}
					case 1:
					{
						if(table_2.getRowCount() != 0) mc.ExcelSave(table_2);
						break;
					}
					case 2:
					{
						if(table_3.getRowCount() != 0) mc.ExcelSave(table_3);
						break;
					}
					case 3:
					{
						if(table.getRowCount() != 0) mc.ExcelSave(table);
						break;
					}
					}

				}
			});
		}
		return btnNewButton_5;
	}
	private JButton getBtnNewButton_6() {
		if (btnNewButton_6 == null) {
			btnNewButton_6 = new JButton("인쇄");
			btnNewButton_6.setRequestFocusEnabled(false);
			btnNewButton_6.setMnemonic('P');//단축키 설정
			btnNewButton_6.setToolTipText("인쇄 단축키: [Alt+P]");
			btnNewButton_6.setFont(new Font("굴림", Font.PLAIN, 11));
			btnNewButton_6.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					try{
						switch(tabbedPane.getSelectedIndex()){
						case 0:
						{
							if(table_1.getRowCount() != 0) table_1.print();
							break;
						}
						case 1:
						{
							if(table_2.getRowCount() != 0) table_2.print();
							break;
						}
						case 2:
						{
							if(table_3.getRowCount() != 0) table_3.print();
							break;
						}
						case 3:
						{
							if(table.getRowCount() != 0) table.print();
							break;
						}
						}

					}catch(Exception ex){
						ex.printStackTrace();
					}
				}
			});
		}
		return btnNewButton_6;
	}
	private JPanel getPanel_8() {
		if (panel_8 == null) {
			panel_8 = new JPanel();
			panel_8.setLayout(new BorderLayout(0, 0));
			panel_8.add(getPanel_9(), BorderLayout.NORTH);
			panel_8.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel_8;
	}
	private JPanel getPanel_10() {
		if (panel_10 == null) {
			panel_10 = new JPanel();
			panel_10.setLayout(new BorderLayout(0, 0));
			panel_10.add(getPanel_11(), BorderLayout.NORTH);
			panel_10.add(getPanel_12(), BorderLayout.CENTER);
		}
		return panel_10;
	}
	private JPanel getPanel_9() {
		if (panel_9 == null) {
			panel_9 = new JPanel();
			panel_9.setBackground(new Color(0, 0, 102));
			panel_9.add(getLabel_4());
			panel_9.add(getTeamYCom());
			panel_9.add(getTeamMCom());
			panel_9.add(getTeamCombo());
			panel_9.add(getButton_1());
			panel_9.add(getLblresult3());
		}
		return panel_9;
	}
	private JComboBox getTeamCombo() {
		if (teamCombo == null) {
			teamCombo = new JComboBox();
			teamCombo.setFont(new Font("굴림", Font.PLAIN, 11));

			teamCombo.addItem("부서");
			teamCombo.addItem("재경부");
			teamCombo.addItem("기획부");
			teamCombo.addItem("홍보부");
			teamCombo.addItem("개발부");
			teamCombo.addItem("마케팅부");
			teamCombo.addItem("총무부");

		}
		return teamCombo;
	}
	private JComboBox getTeamMCom() {
		if (teamMCom == null) {
			teamMCom = new JComboBox();
			teamMCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su.length;i++){
				teamMCom.addItem(su[i]+"월");
			}
			teamMCom.setSelectedIndex(12);

		}
		return teamMCom;
	}
	private JComboBox getTeamYCom() {
		if (teamYCom == null) {
			teamYCom = new JComboBox();
			teamYCom.setFont(new Font("굴림", Font.PLAIN, 11));

			for(int i=0;i<su2.length;i++){
				teamYCom.addItem(su2[i]+"년");
			}
			teamYCom.setSelectedIndex(11);

		}
		return teamYCom;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}
	private JTable getTable() {
		if (table == null) {
			//colName.remove(colName.size()-1);
			model4 = new DefaultTableModel(colName, 0) {
				// 셀 내용 수정 불가
				public boolean isCellEditable(int rowIndex, int mColIndex) {
					return false;
				}
			};
			
			table = new JTable(model4);
			table.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent e) {
					mouseC(table,3);
				}
			});
			table.setAutoCreateRowSorter(true);
			mc.tableCellCenter(table);
			mc.tableCellRight(table);
		}
		return table;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("년월 조회");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JButton jb = (JButton)e.getSource();
					String name = jb.getText();
					String dy = (String)comboBox.getItemAt(comboBox.getSelectedIndex());
					String dm = (String)comboBox_1.getItemAt(comboBox_1.getSelectedIndex());
					search(name, dy, dm, "", model5);
					int rowCNT1 = model5.getRowCount();
					lblresult1.setText(rowCNT1+"건이 검색 되었습니다");
				}
			});
			btnNewButton.setFont(new Font("굴림", Font.PLAIN, 11));
		}
		return btnNewButton;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("직책 조회");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JButton jb = (JButton)e.getSource();
					String name = jb.getText();
					String ly = (String)lvYCom.getItemAt(lvYCom.getSelectedIndex());
					String lm = (String)lvMCom.getItemAt(lvMCom.getSelectedIndex());
					String lv = (String)lvCombo.getItemAt(lvCombo.getSelectedIndex());
					search(name, ly, lm, lv, model2);
					int rowCNT2 = model2.getRowCount();
					lblresult2.setText(rowCNT2+"건이 검색 되었습니다");
				}
			});
			button.setFont(new Font("굴림", Font.PLAIN, 11));
		}
		return button;
	}
	private JButton getButton_1() {
		if (button_1 == null) {
			button_1 = new JButton("부서 조회");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JButton jb = (JButton)e.getSource();
					String name = jb.getText();
					String ty = (String)teamYCom.getItemAt(teamYCom.getSelectedIndex());
					String tm = (String)teamMCom.getItemAt(teamMCom.getSelectedIndex());
					String tc = (String)teamCombo.getItemAt(teamCombo.getSelectedIndex());
					search(name, ty, tm, tc, model4);
					int rowCNT3 = model4.getRowCount();
					lblresult3.setText(rowCNT3+"건이 검색 되었습니다");
				}
			});
			button_1.setFont(new Font("굴림", Font.PLAIN, 11));
		}
		return button_1;
	}

	//조회 일괄 처리
	public void search(String name, String y, String m, String find,DefaultTableModel model){
		String ym="";
		//String[] yy = y.split("년");
		//String[] mm = m.split("월");
		y = y.substring(0, 2);
		m = m.substring(0, 2);
		if(y.equals("전체") && m.equals("전체")) ym = "";
		else if(!y.equals("전체") && m.equals("전체")) ym= y+"/";
		else if(y.equals("전체") && !m.equals("전체")) ym= "%/"+m+"/";
		else ym = y+"/"+m+"/";
		if(name.contains("년월")) ym1=ym;
		if(name.contains("직책")){
			ym2=ym;
			find =" where position='"+find+"'";
		}
		else if(name.contains("부서")){
			ym3=ym;
			find =" where team='"+find+"'";
		}
		else if(name.contains("검색")){
			ym4=ym;
			find =" where memberid='"+find+"'";
		}
		
		if(!name.contains("검색")) db.search(ym,find,model);
		else db.searchSabern(ym,find,model);
	}

	private JPanel getPanel_11() {
		if (panel_11 == null) {
			panel_11 = new JPanel();
			panel_11.add(getLblNewLabel_2());
			panel_11.add(getYear());
			panel_11.add(getBtnNewButton_1());
		}
		return panel_11;
	}
	private JPanel getPanel_12() {
		if (panel_12 == null) {
			panel_12 = new JPanel();
		}
		return panel_12;
	}
	private JComboBox getYear() {
		if (year == null) {
			
			year = new JComboBox();
			year.addMouseListener(new MouseAdapter() {
				
				
			});
			year.setFont(new Font("굴림", Font.PLAIN, 11));
			
			for(int i=0;i<su2.length-1;i++){
				year.addItem(su2[i]+"년");
			}
		}
		return year;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("년별 조회");
		}
		return lblNewLabel_2;
	}
	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("조회");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					String ye = (String)year.getSelectedItem();
					String yeap[] = ye.split("년");
					p.total(yeap[0]);
					
					panel_12.removeAll();
					panel_12.updateUI();
					
					JFreeChart chart = p.getChart(); // JFreeChart
					ChartPanel panel = new ChartPanel(chart);
					panel.setLayout(new BorderLayout(0,0));
					panel.setBounds(0, 0, 400, 300);
					panel.setVisible(true);
					panel_12.add(panel, BorderLayout.CENTER);
					panel_12.updateUI();
					
				}
			});
		}
		return btnNewButton_1;
	}
	private JLabel getLblNewLabel_3() {
		if (lblNewLabel_3 == null) {
			lblNewLabel_3 = new JLabel("                   ");
		}
		return lblNewLabel_3;
	}
	private JLabel getLblresult1() {
		if (lblresult1 == null) {
			lblresult1 = new JLabel("New label");
			lblresult1.setForeground(Color.WHITE);
		}
		return lblresult1;
	}
	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("               ");
		}
		return label;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("               ");
		}
		return label_1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("      ");
		}
		return label_2;
	}
	private JLabel getLblresult2() {
		if (lblresult2 == null) {
			lblresult2 = new JLabel("검색된 데이터가 없습니다");
			lblresult2.setForeground(Color.WHITE);
		}
		return lblresult2;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("               ");
		}
		return label_4;
	}
	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("          ");
		}
		return label_6;
	}
	private JLabel getLabel_7() {
		if (label_7 == null) {
			label_7 = new JLabel(" ");
		}
		return label_7;
	}
	private JLabel getLblresult3() {
		if (lblresult3 == null) {
			lblresult3 = new JLabel("검색된 데이터가 없습니다");
			lblresult3.setForeground(Color.WHITE);
		}
		return lblresult3;
	}
	private JLabel getLblresult4() {
		if (lblresult4 == null) {
			lblresult4 = new JLabel("검색된 데이터가 없습니다");
			lblresult4.setForeground(Color.WHITE);
		}
		return lblresult4;
	}
}

